package org.datacoder.geocoding.datastructures.rectangles

import org.datacoder.geocoding.datastructures.geoshapes.*
import org.datacoder.geocoding.jurisdiction.*

class PairedSegmentTrees implements RectanglesContainingPointFinder {

    private SegmentTree hzTree
    private SegmentTree vtTree

    public PairedSegmentTrees(Collection<Jurisdiction> jurisdictions){
        hzTree = new SegmentTree(jurisdictions, GeoShape.LON)
        vtTree = new SegmentTree(jurisdictions, GeoShape.LAT)
    }

    public Set<Jurisdiction> findRectanglesContainingPoint(GeoPoint gp){
        Set<Jurisdiction> hzJurisdictions = hzTree.findIntervalsContainingPoint(gp.lon)
        Set<Jurisdiction> vtJurisdictions = vtTree.findIntervalsContainingPoint(gp.lat)
        hzJurisdictions.retainAll(vtJurisdictions)
        return hzJurisdictions
    }

}

